﻿@{
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@using SRF.UI.Html
@section header
{
    <script type="text/javascript">
        function search() {
            $(".searchbar").search();
        }
        function resetSearch() {
            //TODO:重设搜索条件
            search();
        }
        function openEditor(action, id) {
            var url, title;
            switch (action) {
                case "add":
                    {
                        url = "edit";
                        title = "新增角色";
                    }
                    break;
                case "update":
                    {
                        url = "edit/" + id;
                        title = "修改角色";
                    }
                    break;
                case "delete":
                    {
                        $.confirm("您确定要删除该角色吗？", "确认删除", function (returnValue) {
                            if (returnValue == "ok") {
                                url = "delete";
                                $.get(url, { id: id }, function (data) {
                                    if (data) {  //发生异常
                                        alert(data);
                                    }
                                    else {
                                        location.reload();
                                    }
                                });
                            };
                        });
                        return;
                    }
                    break;
                case "view":
                    {
                        url = "view/" + id;
                        title = "查看角色";
                        $.dialog({
                            url: url,
                            title: title,
                            height: 300,
                            width: 550,
                            buttons: {
                                "关闭": {
                                    "class": "btn btn-primary",
                                    "data-dismiss": 'modal'
                                }
                            },
                            loading: function () {
                                $(this).iframeLoading();
                            }
                        });
                        return;
                    }
                    break; 
            }
            //新增\修改
            $.dialog({
                url: url,
                title: title,
                height: 300,
                width: 550,
                callback: function (returnValue) {
                    location.reload();
                },
                loading: function () {
                    $(this).iframeLoading();
                }
            });
        }
        function onDialogClosed(id, returnValue) {
            if (returnValue == true)
                location.reload();
        }
    </script>
}
@section toolbar
{
    <input type="button" value="新增" class="btn btn-primary" style="float: right" onclick="return openEditor('add');" />
}
@section searchbar{
    @*    <div class="searchbar control-group" style="margin-bottom: 0px">
        <div class="controls" style="margin-left: 0px"> 
            <!--搜索条件-->
            <input type="submit" class="btn btn-primary" value="搜索" /><input type="button" class="btn"
                value="重置" onclick="resetSearch();" /></div>
    </div>*@
}
@section list{
    <table class="grid table table-striped table-bordered bootstrap-datatable datatable">
        <thead>
            <tr> 
                <th>名称</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (System.Data.DataRow row in Model.Rows)
            {  
                <tr> 
                    <td style="width:200px">@row["Name"]</td> 
                    <td>@row["Remark"]</td> 
                    <td class="action" style="width: 80px">
                        <a class="icon-edit" href="javascript:openEditor('update','@row["Id"]');" title="修改"></a>
                        <a class="icon-book" href="javascript:openEditor('view','@row["Id"]');" title="查看"></a>
                        <a class="icon-remove" href="javascript:openEditor('delete','@row["Id"]');" title="删除"></a>
                    </td>
                </tr>
            }</tbody>
    </table>
}
